﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorkflowCore.Interface;
using WorkflowCore.Models;
using WorkflowCore2210A.Application.Dto.Input;
using WorkflowCore2210A.Domain;

namespace WorkflowCore2210A.Application.Steps
{
    public class EndStep : StepBody
    {
        private readonly WorkflowCoreContext _db;

        public EndStep(WorkflowCoreContext db)
        {
            _db = db;
        }

        public override ExecutionResult Run(IStepExecutionContext context)
        {
            Console.WriteLine("流程结束。");

            // 将流程状态修改为结束
            context.Workflow.Status = WorkflowStatus.Complete;


            var instance = _db.WorkflowInstance.FirstOrDefault(x=>x.WorkflowId == context.Workflow.Id);
            instance.Status = "通过";
            instance.CompelteTime = DateTime.Now;
            instance.AuditUserName = "";
            instance.StepName = context.Step.Name;
            _db.SaveChanges();


            return ExecutionResult.Next();
        }
    }
}
